const fs = require('fs')
const tinify = require('tinify')
tinify.key = "xxxxx"

tinify.validate(err => {
    if (err) {
        throw err
    } else {
        // console.log(tinify.compressionCount)
        fs.readdir('./xin', (err, files) => {
            console.log(files)
            files.forEach(file => {
                // tinify.fromFile('./xin/' + file).toFile('./xins/' + file)
                setTimeout(() => {
                    let source = tinify.fromFile('./xin/' + file)
                    setTimeout(() => {
                        source.toFile('./xins/' + file)
                    }, 2000)
                }, 1000)
            })
        })
        // console.log(tinify.compressionCount)
    }
})

// 运行 node index.js 两次才全部下载完成
